package com.xxxx.paipaicars.controller;

import com.xxxx.paipaicars.bean.dto.UserDTO;
import com.xxxx.paipaicars.bean.vo.UserVO;
import com.xxxx.paipaicars.common.RandomNickConfig;
import com.xxxx.paipaicars.common.Response;
import com.xxxx.paipaicars.config.auth_phase.AccessPhase;
import com.xxxx.paipaicars.service.IUserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by frank on 2023/2/14.
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/login")
public class LoginController {

    @Resource
    private IUserService iUserService;
    @Resource
    private RandomNickConfig randomNickConfig;


    /**
     * 注册
     *
     * @param userDTO 用户传参实体
     * @return 通用返回值
     */
    @AccessPhase(name = "com.xxxx.paipaicars.config.auth_phase.UserAccessPhase")
    @PostMapping("/register")
    public Response register(@RequestBody UserDTO userDTO) {
        Boolean flag = iUserService.register(userDTO);
        return Response.success(flag);
    }

    /**
     * 发送短信验证码
     *
     * @param userDTO 用户传参实体
     * @return 通用返回值
     */
    @PostMapping("/sendMsgCode")
    public Response sendMsgCode(@RequestBody UserDTO userDTO) {
        String msgCode = iUserService.sendMsgCode(userDTO);
        return Response.success(msgCode);
    }

    /**
     * 重置用户密码
     *
     * @param userDTO 用户传参实体
     * @return 通用返回值
     */
    @PostMapping("/updateUserPassword")
    public Response updateUserPassword(@RequestBody UserDTO userDTO) {
        Boolean flag = iUserService.updateUserPassword(userDTO);
        return Response.success(flag);
    }

    /**
     * 手机验证码登录
     */
    @PostMapping("login_by_msg_code")
    public Response loginByMsgCode(@RequestBody UserDTO userDTO) {
        UserVO userVO = iUserService.loginByMsgCode(userDTO);
        return Response.success(userVO);
    }



    /**
     * 退出登录
     */
    @PostMapping("/logout")
    public Response logout(@RequestBody UserDTO userDTO) {
        Boolean flag = iUserService.logout(userDTO);
        return Response.success(flag);
    }


    @AccessPhase(name = {"com.xxxx.paipaicars.config.auth_phase.AdminAccessPhase"})
    public Response adminTest(){
        // 这里的接口只允许管理员访问,普通用户无法访问
        return null;
    }




}
